//
//  ViewController.swift
//  UIView进行3D旋转
//
//  Created by quanhao huang on 2019/9/28.
//  Copyright © 2019 demo. All rights reserved.
//

import UIKit
import QuartzCore

class ViewController: UIViewController {

    @IBOutlet weak var rotationView: UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //指定视图在y轴方向旋转
        let animation = CABasicAnimation(keyPath: "transform.rotation.y")
        //指定视图从0角度旋转一个完整的圆周
        animation.fromValue = 0.0
        animation.toValue = .pi * 2.0
        //动画持续时间4秒。并无限循环
        animation.repeatCount = Float.infinity
        animation.duration = 4.0
        
        self.rotationView.layer.add(animation, forKey: "spin")
        
        var transform = CATransform3DIdentity
        //m 34视角尖锐度 给一种靠近变大的感觉
        transform.m34 = 1.0/500.0
        
        self.rotationView.layer.transform = transform
        
        //停止某一种动画使用
//        self.rotationView.layer.removeAnimation(forKey: "spin")
        //停止所有动画
//        self.rotationView.layer.removeAllAnimations()
    }


}

